import {getSongList,getSongs}  from  '../request/api'
let myaduio =null
Page({
  data: {
    detail:{},
    //存放歌单所有歌曲
    arr2:[]
  },
  demo(e){
  let id = e.currentTarget.dataset.id
  //let url =`https://music.163.com/song/media/outer/url?id=${id}.mp3`
  wx.navigateTo({
      url:'../../pages/play/play?id='+id,
  })
  },

      //获取详情页数据
      async getDetais(id){
        let res = await getSongList(id)
        let arr1 =[]
        res.data.playlist.trackIds.forEach((v)=>{
            arr1.push(v.id)

        })

        this.demo1(arr1.join(','))
        this.setData({
            detail:res.data.playlist
        })
      }, 
  async demo1(ids){
    let res = await getSongs(ids)
    console.log("歌曲详情",res);
    //赋值
    res.data.songs.forEach((item)=>{
      let arr = []
      item.ar.forEach((v)=>{
        arr.push(v.name)
      })
      item.demo3 = arr.join('/')
    })
    this.setData({
        arr2:res.data.songs
    })
  },
       

  onLoad: function(options) {
    //this.getDetais(19723756)
    this.getDetais(options.id)
    myaduio = wx.createInnerAudioContext()
  },


  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})